package com.cuit.jifver.weibo;

import java.io.File;

import com.cuit.jifver.weibo.db.Database;
import com.cuit.jifver.weibo.logic.MainService;
import com.cuit.jifver.weibo.net.RequestCache;
import com.cuit.jifver.weibo.utils.ImageCache;
import com.cuit.jifver.weibo.utils.ImageCacheList;
import com.cuit.jifver.weibo.utils.LogUtil;
import com.cuit.jifver.weibo.utils.Util;

import android.app.Application;

public class WeiboApp extends Application
{
	private static WeiboApp instance;
	
	/**
	 * Image cache, one for all activities and orientations
	 */
	private ImageCache mImageCache;
	private ImageCacheList mImageCacheList;
	/**
	 * Web request cache, one for all activities and orientations
	 */
	private RequestCache mRequestCache;

	public WeiboApp()
	{
		instance = this;
	}
	
	public static WeiboApp getInstance()
	{
		if (instance == null)
		{
			instance = new WeiboApp();
		}
		
		return instance;
	}
	
	@Override
	public void onCreate()
	{
		super.onCreate();
		setCachePath();
		new MainService();
		LogUtil.i(this, "MianService="+MainService.mainService);
		mImageCache = new ImageCache();
		mImageCacheList = new ImageCacheList();
		mRequestCache = new RequestCache();		
		Database.getInstance().setContent(getApplicationContext());
		Database.getInstance().createDatabase();
		
	}
	
	public void setCachePath()
	{
		 File f = new File(Util.imgFilePath);
    	 if(!f.exists())
            {
            	f.mkdirs();
            }
	}
	
	public ImageCache getImageCache() {
		return mImageCache;
	}
	
	public ImageCacheList getImageCacheList() {
		return mImageCacheList;
	}

}
